from pages import IndexPage
from pages.BasePage import BasePage


class LoginPage(BasePage):
    """
        登录页面
    """

    login_btn = ("xpath", '//button[text()="登录"]')  # 登录按钮
    login_account_btn = ("xpath", '//*[text()=" 账号密码 "]')  # 账号密码按钮
    login_account = ("xpath", '//input[@tabindex="1"]')  # 账号文本框
    login_password = ("xpath", '//input[@tabindex="2"]')  # 密码文本框
    opt_checkBox = ("xpath", '//div/p[@class="protocol-box"][2]/label')  # 我已阅读并同意服务协议和隐私政策-复选框
    login_button = ("xpath", '//span[text()=" 登录 "]')

    def login(self, username, password):
        """
        登录
        :param username:
        :param password:
        :return:
        """

        self.driver.maximize_window()
        # 点击左上角“登录”按钮
        self.wait_find_element(*self.login_btn).click()
        # 点击账号密码按钮
        self.wait_find_element(*self.login_account_btn).click()
        # 点击登录账号文本框
        self.wait_find_element(*self.login_account).send_keys(username)
        # 输入密码
        self.wait_find_element(*self.login_password).send_keys(password)
        # 点击勾选“我已阅读并同意服务协议和隐私政策”复选框按钮
        self.wait_find_element(*self.opt_checkBox).click()
        # 点击登录按钮
        self.wait_find_element(*self.login_button).click()
        return IndexPage
